package com.woniuxy01;

import java.util.Arrays;

/**
 * @author 作者
 * @create 2025-07-24 9:55
 */
public class Test02 {
    public static void main(String[] args) {
        Feeder feeder = new Feeder();
        Animal[] animals = new Animal[3];
        animals[0] = new Cat("ca1",1,100);
        animals[1] = new Cat("ca2",1,100);
        animals[2] = new Dog("dog1",1,100);
        System.out.println(Arrays.toString(animals));
        for(Animal animal : animals){
            feeder.play(animal);
        }

    }

    private static void test04() {
        Animal animal=new Animal();
        Cat cat=new Cat();

        animal=cat;
        //向下转型--假转型
        cat= (Cat) animal;
        System.out.println("程序结束");
    }

    private static void test03() {
        Animal animal=new Animal();
        Cat cat=new Cat();

        //向上转型--ok
//        animal=cat;

        //向下转型--真转型，animal强制类型转换，编译通过，运行异常
//        cat= (Cat)animal ;
        System.out.println("程序结束");
    }

    private static void test02() {
        Feeder feeder = new Feeder();
        Animal[] animals = new Animal[3];
        animals[0] = new Cat("ca1",1,100);
        animals[1] = new Cat("ca2",1,100);
        animals[2] = new Dog("dog1",1,100);
        System.out.println(Arrays.toString(animals));
        for(Animal animal : animals){
            feeder.play(animal);
        }
    }

    private static void test01() {
        Feeder feeder = new Feeder();
        Animal animal=new Cat();
        feeder.feed(animal);

        feeder.feed(new Dog());
    }
}
